package com.saltedfish.tool.dialog;

import android.app.Activity;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.saltedfish.tool.R;

import butterknife.BindView;
import cn.droidlover.xdroidmvp.log.XLog;
import cn.droidlover.xdroidmvp.popwindow.DialogHelper;

public class UIProgressStatusDialog extends DialogHelper {

    @BindView(R.id.tvBack)
    ImageView tvBack;

    @BindView(R.id.viewLeft1)
    TextView viewLeft1;

    @BindView(R.id.viewLeft2)
    TextView viewLeft2;

    @BindView(R.id.viewLeft3)
    TextView viewLeft3;

    @BindView(R.id.viewLeft4)
    TextView viewLeft4;

    @BindView(R.id.viewLeft5)
    TextView viewLeft5;

    @BindView(R.id.viewLine1)
    RelativeLayout viewLine1;

    @BindView(R.id.viewLine2)
    RelativeLayout viewLine2;

    @BindView(R.id.viewLine3)
    RelativeLayout viewLine3;

    @BindView(R.id.viewLine4)
    RelativeLayout viewLine4;

    @BindView(R.id.viewLine5)
    RelativeLayout viewLine5;

    @BindView(R.id.releateStetus1)
    RelativeLayout releateStetus1;

    @BindView(R.id.releateStetus2)
    RelativeLayout releateStetus2;

    @BindView(R.id.releateStetus3)
    RelativeLayout releateStetus3;

    @BindView(R.id.releateStetus4)
    RelativeLayout releateStetus4;

    @BindView(R.id.releateStetus5)
    RelativeLayout releateStetus5;

    @BindView(R.id.linearProgressStatus)
    LinearLayout linearProgressStatus;

    public UIProgressStatusDialog(Activity context) {
        super(context, R.style.AlertDialogStyle);
        this.mContext = context;
        setFullWidthScreen();
        setGravity(Gravity.BOTTOM);
        setAnimSet(R.style.popRightPopAnim);

    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_ui_progress_status;
    }


    @Override
    protected void initView() {

        tvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                dismiss();
            }
        });

        releateStetus1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                selectProgressStatus("进行中");
            }
        });
        releateStetus2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                selectProgressStatus("暂停");
            }
        });
        releateStetus3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                selectProgressStatus("提前完成");
            }
        });
        releateStetus4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                selectProgressStatus("已延期");
            }
        });
        releateStetus5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                selectProgressStatus("提前完成");
            }
        });

    }

    private String status;

    public void updateStatus(String statu) {
        status = statu;
        selectProgressStatus(statu);

    }

    //case ing = "进行中"
    //    case stop = "暂停"
    //    case noStart = "暂未开始"
    //    case advance = "提前完成"
    //    case delay = "已延期"

    private void selectProgressStatus(String index){
        setDefaultProgressStatus();
        status = index;
        if(index.equals("进行中")){
            viewLine1.setVisibility(View.VISIBLE);
            viewLeft1.setTextColor(mContext.getResources().getColor(R.color.color_3097FF));
        }else  if(index.equals("暂停")){
            viewLine2.setVisibility(View.VISIBLE);
            viewLeft2.setTextColor(mContext.getResources().getColor(R.color.color_3097FF));
        }else  if(index.equals("暂未开始")){
            viewLine3.setVisibility(View.VISIBLE);
            viewLeft3.setTextColor(mContext.getResources().getColor(R.color.color_3097FF));
        }else  if(index.equals("已延期")){
            viewLine4.setVisibility(View.VISIBLE);
            viewLeft4.setTextColor(mContext.getResources().getColor(R.color.color_3097FF));
        }else  if(index.equals("提前完成")){
            viewLine3.setVisibility(View.VISIBLE);
            viewLeft3.setTextColor(mContext.getResources().getColor(R.color.color_3097FF));
            viewLine5.setVisibility(View.VISIBLE);
            viewLeft5.setTextColor(mContext.getResources().getColor(R.color.color_3097FF));
        }

    }

    private void setDefaultProgressStatus(){
        viewLine1.setVisibility(View.GONE);
        viewLine2.setVisibility(View.GONE);
        viewLine3.setVisibility(View.GONE);
        viewLine4.setVisibility(View.GONE);
        viewLine5.setVisibility(View.GONE);

        viewLeft1.setTextColor(mContext.getResources().getColor(R.color.color_333333));
        viewLeft2.setTextColor(mContext.getResources().getColor(R.color.color_333333));
        viewLeft3.setTextColor(mContext.getResources().getColor(R.color.color_333333));
        viewLeft4.setTextColor(mContext.getResources().getColor(R.color.color_333333));
        viewLeft5.setTextColor(mContext.getResources().getColor(R.color.color_333333));

    }
    @Override
    protected void initData() {
        linearProgressStatus.setVisibility(View.GONE);
    }

    @Override
    protected void dialogDismiss() {
        dismiss();
    }

    @Override
    public void dismiss() {
        XLog.e("---dismiss----状态选择-------"+status);

        if (listener != null) {
            listener.onClick(status);
        }

        mContext.getWindow().setStatusBarColor(mContext.getResources().getColor(R.color.color_white));
        super.dismiss();
    }

}
